using System ;
using System.Xml.Linq ;

namespace Gleed2D.InGame
{
// ReSharper disable UnusedMember.Global
	public class LayerItem
	{
		readonly ItemProperties _properties ;
        readonly Type _itemType;
        readonly TextureItemProperties _textureProperties;
        readonly RectangleItemProperties _rectangleProperties;

		public LayerItem( XElement xml )
		{
			string propertiesTypeAsText = xml.CertainAttribute( @"ClrTypeOfProperties" ).Value ;
			Type typeOfProperties = Type.GetType( propertiesTypeAsText ) ;
			string justTheName = typeOfProperties.Name ;
            _itemType = typeOfProperties;

			_properties = (ItemProperties)xml.Element( justTheName ).DeserializedAs( typeOfProperties ) ;


            if (_itemType == typeof(TextureItemProperties))
            {
                _textureProperties = (TextureItemProperties)xml.Element(justTheName).DeserializedAs(typeOfProperties);
            }
            else if (_itemType == typeof(RectangleItemProperties))
            {
                _rectangleProperties = (RectangleItemProperties)xml.Element(justTheName).DeserializedAs(typeOfProperties);
               
            }
            
		}

		public ItemProperties Properties
		{
			get
			{
				return _properties ;
			}
		}

        public Type ItemType
        {
            get
            {
                return _itemType;
            }
        }

        public RectangleItemProperties RectangleItemProperies
        {
            get
            {
                return _rectangleProperties;
            }
        }

        public TextureItemProperties TextureItemProperties
        {
            get
            {
                return _textureProperties;
            }
        }

	}
// ReSharper restore UnusedMember.Global
}